﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Weight.Model;
using System.Data;
using Dapper;
using Weight.Base;
using Dapper.Contrib;
using Dapper.Contrib.Extensions;

namespace Weight.Dal
{
    public  class DalWeightField
    {
        public IEnumerable<WeightFieldEntity> GetWeightField()
        {
            using(IDbConnection conn = SessionFactory.CreateConnection())
            {
                return  conn.GetAll<WeightFieldEntity>();
            }
        }

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public bool InsertBatch(List<WeightFieldEntity> list)
        {
            using (IDbConnection conn = SessionFactory.CreateConnection())
            {
                IDbTransaction tran =  conn.BeginTransaction();
                conn.DeleteAll<WeightFieldEntity>(tran);
                long count = conn.Insert(list,tran);
                if(count > 0)
                {
                    tran.Commit();
                    return true;
                }
                else
                {
                    tran.Rollback();
                    return false;
                }
               
            }
        }

    }
}
